// 修改记录
const { N, needParam } = require("../../utils");
// const { getWhereStr } = require("./_utils");
// const { getSomeFieldNames, getStandFieldNames } = require("../../compile/mysql/_utils");
const { getUpdateFieldsStr } = require("./update");
const { getInsertFieldsStr } = require("./insert");

module.exports = {
  /**
   * 修改表格数据
   * @param {string} tableName 表名称
   * @param {object} fieldMap 要修改的字段数据
   * @param {object} { where, order, limits, group, having } sql配置
   */
  // insertOrUpdateTable('user', [["create_id", "type", "status"],["3", 13, 1]], {status: 'not status' }}) // // 1是新增时候的默认值
  //   ["create_id", "type", "status"],
  //   ["3", 13, 1], // 1是新增时候的默认值
  insertOrUpdateTable(tableName = needParam(), withKeysRows = [], fieldMap = needParam()) {
    const updateStr = getUpdateFieldsStr(fieldMap);
    const insertStr = getInsertFieldsStr(tableName, withKeysRows);
    // return `INSERT INTO operate_status (create_id, type, status) VALUES ('3', 13, 1) ON DUPLICATE KEY UPDATE status = NOT status;`
    return `INSERT INTO ${tableName} ${insertStr} ON DUPLICATE KEY UPDATE ${updateStr};`;
  },
};
